package com.quanyan.runningriding.web.running;

import com.quanyan.api.APIResponse;
import com.quanyan.runningriding.entity.vo.run.resp.RespVersionVo;
import com.quanyan.runningriding.service.RunUpdatedService;
import com.quanyan.runningriding.util.RunEnum;
import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * Created by liubin on 2016/10/31 0031.
 */
@RestController
@RequestMapping(value = "/api/run")
public class UpdatedAdminController {
    @Autowired
    private RunUpdatedService runUpdatedService;
    private Logger logger = LoggerFactory.getLogger(UpdatedAdminController.class);
    @RequestMapping(value = "/updatedVersion", method = RequestMethod.POST)
    public APIResponse<RespVersionVo> updatedVersion(@RequestBody Map<String, Object> paramMap){
        Byte platform = MapUtils.getByte(paramMap, "platform");
        if (platform == null) {
            return APIResponse.returnFail(RunEnum.PARAMETER_NOT_VALID);
        }

        String appVersion = MapUtils.getString(paramMap,"appVersion");
        if (appVersion == null) {
            return APIResponse.returnFail(RunEnum.PARAMETER_NOT_VALID);
        }
        return runUpdatedService.updatedVersion(platform,appVersion);
    }


}
